package com.mk.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.beetl.sql.core.annotatoin.AssignID;
import org.beetl.sql.core.annotatoin.Param;
import org.beetl.sql.core.annotatoin.Table;
import org.beetl.sql.core.mapper.BaseMapper;
import org.osgl.util.S;

import javax.persistence.Transient;
import java.util.Map;

@Table(name = "cp_msg")
@SuppressWarnings("unused")
public class CpMsg {
    @AssignID
    private String mid;
    //扩展参数
    private String advparams;
    private String appid;
    //所属企业
    private String coid;
    //是否用于展示
    private String forshow;
    //级别
    private String mlevel;
    //打开页面标题
    private String mopentitle;
    //图片
    private String mpic;
    //消息内容
    private String msg;
    //创建时间
    private String mtime;
    //标题
    private String mtitle;
    //顶级类型
    private String mtopone;
    //打开地址
    private String murl;
    //电话
    private String phone;
    //openid
    private String openid;
    //它的展示消息ID
    private String pmid;
    //是否已读
    private String readabled;
    //阅读时间
    private String readtime;
    //接受消息的用户id
    private String userid;
    //模板参数
    private String wparams;

    //标题
    private String title;
    //    private String userid;
    //消息类型,随便定义,为了以后按类型查看消息的扩展
    private String mtype;
    //消息参数,json类型
    private String paramstring;
    //平台消息id
    private String mtid;
    //参数扩展
    @Transient
    private Map<String, String> params;
    //时间
//    private String mtime;
    //0=未读 1=已读 2=删除
    private String mstate;
    //图片
    private String pic;

    //消息类型
    private String msgtype;

    //附件名称
    private String attachmentname;
    //附件id
    private String attachmenturl;

    public CpMsg() {
    }

    public CpMsg(CpMsg msg_old) {
        setTitle(msg_old.getTitle());
        setMtime(msg_old.getMtime());
        setMstate(msg_old.getMstate());
        setMsg(msg_old.getMsg());
        setMtype(msg_old.getMtype());
        setMurl(msg_old.getMurl());
        setParams(msg_old.getParams());
        setWparams(msg_old.getWparams());
        setOpenid(msg_old.getOpenid());
        if (params != null) {
            if (S.isNotBlank(title)) params.put("mtitle", title);
            if (S.isNotBlank(murl)) params.put("murl", murl);
            if (S.isNotBlank(pic)) params.put("pic", pic);
        }
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getMsgtype() {
        return msgtype;
    }

    public void setMsgtype(String msgtype) {
        this.msgtype = msgtype;
    }

    public String getAttachmentname() {
        return attachmentname;
    }

    public void setAttachmentname(String attachmentname) {
        this.attachmentname = attachmentname;
    }

    public String getAttachmenturl() {
        return attachmenturl;
    }

    public void setAttachmenturl(String attachmenturl) {
        this.attachmenturl = attachmenturl;
    }

    public String getMtid() {
        return mtid;
    }

    public void setMtid(String mtid) {
        this.mtid = mtid;
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    public String getMtime() {
        return mtime;
    }

    public void setMtime(String mtime) {
        this.mtime = mtime;
    }

    public String getMstate() {
        return mstate;
    }

    public void setMstate(String mstate) {
        this.mstate = mstate;
    }

    @Deprecated
    public String getParamstring() {
        return JSON.toJSONString(params);
    }

    @Deprecated
    public void setParamstring(String paramstring) {
        this.paramstring = paramstring;
        if (params != null) {
            JSONObject oo = JSON.parseObject(paramstring);
            for (Object o : oo.entrySet()) {
                Map.Entry entry = (Map.Entry) o;
                if (entry.getValue() != null) {
                    params.put(entry.getKey().toString(), entry.getValue().toString());
                }
            }
        }
    }

    public String getMtype() {
        return mtype;
    }

    public void setMtype(String mtype) {
        this.mtype = mtype;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getMid() {
        return mid;
    }

    public void setMid(String mid) {
        this.mid = mid;
        if (params != null) params.put("mid", mid.toString());
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getMurl() {
        return murl;
    }

    public void setMurl(String murl) {
        this.murl = murl;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, String> getParams() {
        return params;
    }

    public void setParams(Map<String, String> params) {
        this.params = params;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAdvparams() {
        return advparams;
    }

    public void setAdvparams(String advparams) {
        this.advparams = advparams;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getCoid() {
        return coid;
    }

    public void setCoid(String coid) {
        this.coid = coid;
    }

    public String getForshow() {
        return forshow;
    }

    public void setForshow(String forshow) {
        this.forshow = forshow;
    }

    public String getMlevel() {
        return mlevel;
    }

    public void setMlevel(String mlevel) {
        this.mlevel = mlevel;
    }

    public String getMopentitle() {
        return mopentitle;
    }

    public void setMopentitle(String mopentitle) {
        this.mopentitle = mopentitle;
    }

    public String getMpic() {
        return mpic;
    }

    public void setMpic(String mpic) {
        this.mpic = mpic;
    }

    public String getMtitle() {
        return mtitle;
    }

    public void setMtitle(String mtitle) {
        this.mtitle = mtitle;
    }

    public String getMtopone() {
        return mtopone;
    }

    public void setMtopone(String mtopone) {
        this.mtopone = mtopone;
    }

    public String getPmid() {
        return pmid;
    }

    public void setPmid(String pmid) {
        this.pmid = pmid;
    }

    public String getReadabled() {
        return readabled;
    }

    public void setReadabled(String readabled) {
        this.readabled = readabled;
    }

    public String getReadtime() {
        return readtime;
    }

    public void setReadtime(String readtime) {
        this.readtime = readtime;
    }

    public String getWparams() {
        return wparams;
    }

    public void setWparams(String wparams) {
        this.wparams = wparams;
    }

    public interface Mapper extends BaseMapper<CpMsg> {

        /**
         * 查看消息
         *
         * @param coid
         * @param userid
         * @param mid
         * @return
         */
        CpMsg viewMyMsg(@Param("coid") String coid, @Param("userid") String userid, @Param("mid") String mid);
    }
}